import { BasicFetchResult } from '../model/baseModel';
import { defHttp } from '@/utils/http/axios';
import { downloadBlob } from '@/utils/file/download';
const api = '/flow/def';
export const page = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/page', params });
export const list = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/list', params });
export const readXml = (deployId: string) =>
  defHttp.get({ url: `${api}/readXml/${deployId}` });
export const save = (params?: any) =>
  defHttp.post({ url: api + '/save', params });
export const edit = (params?: any) =>
  defHttp.post({ url: api + '/edit', params });
export const del = (key: string) =>
  defHttp.post({ url: `${api}/delete?key=${key}`, timeout: -1 });
export const exp = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: api + '/export', params },
        { isReturnNativeResponse: true },
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
export const bindFlow = ({ defKey, formId }) =>
  defHttp.post({ url: api + '/bindFlow', params: { defKey, formId } });
export const getFormInfo = (params) => {
  return defHttp.get<BasicFetchResult<any>>({
    url: api + '/getFlowInfo',
    params,
  });
};
